#!/usr/bin/python3
# -*- coding: utf-8 -*-

import sys
# sys.path.append('/opt/work/caffe/python')
sys.path.insert(0, '.')

import argparse
import os

out_path = r'/rootfs/media/kasim/Data1/data/VideoCropFace/face_image_bbox_filter.txt'
filter_file_list = r'/rootfs/media/kasim/Data1/data/VideoCropFace/face_select/face_image_filter_filter.txt'
bbox_file_list = r'/rootfs/media/kasim/Data1/data/VideoCropFace/face_image_filter.txt'


def main():
    filter_file_set = set()
    with open(filter_file_list, 'r') as file:
        for line in file.readlines():
            file_name = line.strip()
            filter_file_set.add(file_name)

    out_infos = []
    with open(bbox_file_list, 'r') as file:
        for line in file.readlines():
            lines = line.split()
            file_name = lines[0]
            bbox = lines[1]
            if file_name not in filter_file_set:
                continue
            out_info = '{} {}\n'.format(file_name, bbox)
            out_infos.append(out_info)

    with open(out_path, 'w') as out_file:
        out_infos.sort()
        for out_info in out_infos:
            out_file.write(out_info)
    os.system('chmod a+wr {}'.format(out_path))


if __name__ == '__main__':
    main()
